/*
 * CS_STAMINA_INFO.cpp
 *
 *  Created on: 2014. 4. 14.
 *      Author: mega
 */

#include "../../User.h"
#include "../../Command.h"
#include "../../NLogic/Stamina.h"
#include "../../NResource/Static.h"

namespace ProjectZ { namespace NCommand {

static void SendAckStaminaInfo(User * pUser, int ack, int remainSec)
{
	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	*pAck << static_cast<int16_t>(ack);
	if (ACK_OK == ack)
	{
		*pAck << static_cast<uint16_t>(pUser->GetCharacterInfo().max_stamina);
		*pAck << static_cast<uint16_t>(pUser->GetCharacterInfo().cur_stamina);
		*pAck << static_cast<uint32_t>(remainSec);
	}
	pAck->MakePacket(CMD_SC_STAMINA_INFO);
	pUser->Send(pAck);
}

void Command::CS_STAMINA_INFO(User * pUser, ::Network::Packet * pPacket)
{

/*	CS_STAMINA_INFO			0x3300
	{
	}

	SC_STAMINA_INFO			0x3301
	{
		s16				s16ack;
		u16				u16MaxStamina;		//최대값
		u16				u16CurrnetStamina;	//현재값
		u32				u32RecycleTime;		//다음 갱신까지 남은 시간(초)
	}*/

	PREPARE_PACKET;

	if (false == NResource::Static::Instance().GetContentsOpenResource()->IsOpen(static_cast<int>(ContentsOpen::STAMINA_SYSTEM)))
	{
		DEBUGLOG("%s : Contents is Not Open", __FUNCTION__);
		SendAckStaminaInfo(pUser, ACK_NOT_OPEN, 0);
		return;
	}

	NLogic::Stamina * pStamina = pUser->GetStamina();
	if (NULL == pStamina)
	{
		DEBUGLOG("%s : pStamina is NULL", __FUNCTION__);
		SendAckStaminaInfo(pUser, ACK_UNKNOWN_ERROR, 0);
		return;
	}

	int remainSec = pStamina->UpdateStaminaRecoveryTime();

	// 응답
	SendAckStaminaInfo(pUser, ACK_OK, remainSec);
}


} /*NCommand*/ } /*ProjectZ*/
